<template>
  <div class="divBox">
    <el-card class="box-card">
<!--      <el-form inline size="small" @submit.native.prevent>-->
<!--        <el-form-item class="el-form-item-align-right">-->
<!--          <el-button icon="el-icon-circle-plus" size="mini" type="primary" @click="openEdit(0)">添加-->
<!--          </el-button>-->
<!--        </el-form-item>-->
<!--      </el-form>-->
      <el-table :data="listData.list" size="mini"
                :header-cell-style=" {fontWeight:'bold',background:'#f8f8f9',color: '#515a6e',height:'40px'}" border>
        <el-table-column label="ID" prop="id" width="120"></el-table-column>
        <el-table-column align="center" label="序号" prop="sort" min-width="220"/>
        <el-table-column align="center" label="缴费金额" prop="quota" min-width="130"/>
        <el-table-column align="center" label="创建时间" prop="createTime" min-width="130"/>
        <el-table-column align="center" label="操作" min-width="180" fixed="right">
          <template slot-scope="scope">
            <el-button icon="el-icon-edit" size="mini" type="primary" @click="openEdit(1,scope.row)"
                       v-has-permi="['admin:notice:save']">编辑
            </el-button>
<!--            <el-button icon="el-icon-delete" size="mini" type="danger" @click="handlerDelete(scope.row.id)"-->
<!--                       v-has-permi="['admin:notice:delete']">删除-->
<!--            </el-button>-->
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
          :current-page="listPram.page"
          :page-sizes="[10,20,40,60,80,100]"
          layout="total, sizes, prev, pager, next, jumper"
          :total="listData.count"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
      />
    </el-card>
    <el-dialog
        :visible.sync="editDialog.visible"
        :title="editDialog.isCreate === 0? '编辑':'新增'"
        destroy-on-close
        :close-on-click-modal="false"
        top="50px"
        width="1200px">
      <edit
          v-if="editDialog.visible"
          :is-create="editDialog.isCreate"
          :edit-data="editDialog.editDate"
          @hideEditDialog="hideEditDialog"
          ref="editForm"
      />
    </el-dialog>
  </div>
</template>

<script>
import edit from './edit'
import {amountDeleteRow, amountList} from "@/api/payment";
import {checkPermi} from "@/utils/permission";

export default {
  components: {edit},
  data() {
    return {
      listData: {
        list: [], count: 0
      },
      listPram: {
        page: 1,
        limit: 10,
      },
      editDialog: {
        visible: false,
        isCreate: 0, // 0=创建，1=编辑
        editDate: {},
      },
      tableLoading: false,
    }
  },
  mounted() {
    this.imageUrl = process.env.VUE_APP_IMAGE_URL
    this.getList()
  },
  methods: {
    checkPermi,
    getList() {
      this.tableLoading = true
      amountList(this.listPram).then(res => {
        this.listData = res;
      }).finally(() => {
      })
      this.tableLoading = false;
    },
    openEdit(isCreate, editDate) {
      this.editDialog.editDate = editDate;
      this.editDialog.isCreate = isCreate;
      this.editDialog.visible = true
    },
    handlerDelete(id) {
      this.$confirm('确认删除该数据吗？').then(() => {
        const loading = this.$loading({text: '删除中', background: 'rgba(255,255,255,.5)'})
        amountDeleteRow(id).then(() => {
          this.$message.success('删除成功')
          this.getList()
        }).finally(() => {
          loading.close()
        })
      })
    },
    hideEditDialog() {
      this.editDialog.visible = false
      this.getList()
    },
    handleSizeChange(val) {
      this.listPram.limit = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.listPram.page = val
      this.getList()
    },
  }
}
</script>

<style scoped lang="scss">

</style>
